package org.gruposp2p.proyectokarma.gwt.client.domain;

import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.gruposp2p.proyectokarma.gwt.client.util.DateUtils;

public class Document implements java.io.Serializable {

	 private static final long serialVersionUID = 1L;

	 private Long id;
     private Long peerId;
     private String peerName;
     private KarmaParameter karmaParameter;
     private String name = "";
     private Date dateCreated;
     private Date lastUpdated;
     private Date pollingValidTo;
     private Boolean polling;
     private String content = "";
     private Set<Vote> votes = new HashSet<Vote>(0);
     private Set<String> tags;
     private Set<String> options;

     public Document() { }
	
     public Document(Long id, Long peerId, KarmaParameter karmaParameter,
            String name, Date dateCreated, Date lastUpdated, String content, 
            Boolean polling) {
        this.id = id;
        this.peerId = peerId;
        this.karmaParameter = karmaParameter;
        this.name = name;
        this.dateCreated = dateCreated;
        this.lastUpdated = lastUpdated;
        this.content = content;
        this.setPolling(polling);
     }
     
    public Document(Long id, Long peerId, KarmaParameter karmaParameter,
            String name, Date dateCreated, Date lastUpdated, String content,
            Set votes, Set<String> tags, Boolean polling) {
       this.id = id;
       this.peerId = peerId;
       this.karmaParameter = karmaParameter;
       this.name = name;
       this.dateCreated = dateCreated;
       this.lastUpdated = lastUpdated;
       this.content = content;
       this.votes = votes;
       this.tags = tags;
       this.setPolling(polling);
    }
   
    public Long getId() {
        return this.id;
    }
    
    public void setId(Long id) {
        this.id = id;
    }

    public Long getPeerId() {
        return this.peerId;
    }
    
    public void setPeer(Long peerId) {
        this.peerId = peerId;
    }

    public KarmaParameter getKarmaParameter() {
        return this.karmaParameter;
    }
    
    public void setKarmaParameter(KarmaParameter karmaParameter) {
        this.karmaParameter = karmaParameter;
    }
    
    public String getName() {
        return this.name;
    }
    
    public void setName(String name) {
        this.name = name;
    }

    public Date getDateCreated() {
        return this.dateCreated;
    }
    
    public void setDateCreated(Date dateCreated) {
        this.dateCreated = dateCreated;
    }

    public Date getLastUpdated() {
        return this.lastUpdated;
    }
    
    public void setLastUpdated(Date lastUpdated) {
        this.lastUpdated = lastUpdated;
    }
    
    public String getContent() {
        return this.content;
    }
    
    
    public String getTruncatedContent() {
        if (content != null && content.length() > 35) {
        	return content.substring(0, 35) + "...";
        }
    	return this.content;
    }
    
    public void setContent(String content) {
        this.content = content;
    }

    public Set getVotes() {
        return this.votes;
    }
    
    public void setVotes(Set votes) {
        this.votes = votes;
    }

    public  Set<String> getTags() {
        return this.tags;
    }
    
    public void setTags( Set<String> tags) {
        this.tags = tags;
    }

	public void setPolling(Boolean polling) {
		this.polling = polling;
	}

	public Boolean isPolling() {
		return polling;
	}

	public void setOptions(Set<String> options) {
		this.options = options;
	}

	public Set<String> getOptions() {
		return options;
	}

	public void setPollingValidTo(Date pollingValidTo) {
		this.pollingValidTo = pollingValidTo;
	}

	public Date getPollingValidTo() {
		if (pollingValidTo == null) pollingValidTo = DateUtils.getTodayDate();
		return pollingValidTo;
	}

	public void setPeerName(String peerName) {
		this.peerName = peerName;
	}

	public String getPeerName() {
		return peerName;
	}

}


